package org.apache.lucene.util;

import java.io.IOException;

import org.apache.lucene.search.DocIdSetIterator;

public class VIntUtil {
  public static byte[] toBytes(int[] array) throws IOException {
  	SortedVIntList list = new SortedVIntList(array);
  	return list.getBytes();
  }
  
  public static int[] toArray(int size, byte[] bytes) throws IOException {
  	SortedVIntList list = new SortedVIntList(size, bytes);
  	int[] array = new int[size];
  	DocIdSetIterator iterator = list.iterator();
  	int x = 0;
  	while (iterator.next()) {
  		array[x] = iterator.doc();
  		x++;
  	}
  	return array;
  }
}
